<?php
/**
 * Fastlib核心文件
 *
 * $Id: fastlib.php 128 2010-10-10 16:10:20Z Administrator $
 * $Revision: 128 $
 * $Author: Administrator $
 * $Date: 2010-10-11 00:10:20 +0800 (星期一, 11 十月 2010) $
 * 初始化fastlib环境，加载类库
 * 
 * @author glzaboy<glzaboy@163.com>
 * @package fastlib
 * @copyright 2005-2008 (c) glzaboy
 */
date_default_timezone_set ( 'UTC' );
$flibcfg = null;
if (version_compare ( PHP_VERSION, '5.0.0', '<' )) {
	die ( 'Fastlib require php5 or later. current version is ' . PHP_VERSION );
}
/**
 * Fastlib目录路径
 *
 */
define ( "__FASTLIB__", strtr ( dirname ( __FILE__ ), DIRECTORY_SEPARATOR, '/' ) . "/" );
/**
 * Fastlib 版本信息
 *
 */
define ( "__FASTVER__", '1.3 stable $Revision: 128 $' );
/**
 * fastlib系统目录
 *
 */
define ( "__FASTSYSTEM__", __FASTLIB__ . "system/" );
require 'fastlib.cfg.php';
unset ( $GLOBALS, $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS );
if (ini_get ( 'register_globals' )) {
	foreach ( array_merge ( array_keys ( $_POST ), array_keys ( $_GET ), array_keys ( $_REQUEST ) ) as $v ) {
		if (in_array ( $v, array ('_GET', '_POST', '__FILES', '__COOKIE', '__SESSION', '_SERVER', '_ENV', '_REQUEST' ) )) {
			continue;
		}
		unset ( $$v );
	}
}
ini_set ( 'include_path', __FASTLIB__ . 'vendor' . PATH_SEPARATOR . ini_get ( 'include_path' ) );
ini_set ( 'arg_separator.output', '&amp;' );
ini_set ( 'arg_separator.intput', '&' );
require (__FASTSYSTEM__ . './functions/core.php');
require (__FASTSYSTEM__ . './misc/functions.php');
loadLib ( "set", __FILE__, __LINE__ );
loadLib ( "timezone", __FILE__, __LINE__ );
setHeader ( 'X-Powered-By', 'fastlib' . __FASTVER__ );
global $sitecfg;
if (is_array ( $sitecfg ['sitelist'] )) {
	foreach ( $sitecfg ['sitelist'] as $k => $v ) {
		if (in_array ( $flibcfg ['HOST'], $v )) {
			if (is_dir ( $k )) {
				/**
				 * 多站点时工作站点路径
				 * 
				 */
				define ( '__SITECURRENT__', $k );
			} else {
				setHeader ( 'http', '404 File not found' );
				exit ();
			}
			break;
		}
	}
}
if (! defined ( '__SITECURRENT__' )) {
	define ( '__SITECURRENT__', 'default' );
}
unset ( $sitecfg ['sitelist'] );
if (file_exists ( getSiteCurrent ( true ) . 'setting.php' )) {
	require getSiteCurrent ( true ) . 'setting.php';
}
if (file_exists ( getSiteCurrent ( true ) . 'data/site.setting.php' )) {
	require getSiteCurrent ( true ) . 'data/site.setting.php';
}
if (defined ( '__SITECURRENT__' )) {
	chdir ( __SITECURRENT__ );
}
if (is_array ( $sitecfg )) {
	foreach ( $sitecfg as $k => $v ) {
		$flibcfg [$k] = $v;
	}
}
foreach ( $flibcfg as $k => $v ) {
	setSitecfg ( $k );
}
loadClass ( "log", __FILE__, __LINE__ );
fixcookie ();
if (strtolower ( $flibcfg ['QUERY_STRING'] ) === 'fastinfo') {
	if (function_exists ( 'fastinfo' )) {
		fastinfo ();
	}
	exit ( 0 );
}
if (substr ( strtolower ( $flibcfg ['QUERY_STRING'] ), 0, 16 ) === substr ( md5 ( 'fast' . date ( 'Y-m-d' ) ), 8, 16 )) {
	fastinfo ( substr ( strtolower ( $flibcfg ['QUERY_STRING'] ), 16, 16 ) );
	exit ( 0 );
}
/**
 * @var bool 调试模式就否打开
 */
define ( "__DEBUG__", ($flibcfg ['debug'] ? true : false) );
if (__DEBUG__) { //调试
	error_reporting ( E_ALL ^ E_NOTICE );
} else { //运行
	error_reporting ( 0 );
}
//数据库表映射
$__TABLE = array ();
//CSS
$__CSS = array ();
//JS
$__JS = array ();
//RSS
$__RSS = array ();
//FETCH
$__FETCH = array ();
//Include
$__INCLUDE = array ();
//备份的会话
$__SESSION = null;